package com.itheima.flowcontrol.demo;

import java.util.Random;
import java.util.Scanner;

/**
 * 猜数字小游戏
 */
public class RandomTest2 {
    public static void main(String[] args) {
        //1.先随机生成一个1-100之间的数据
        Random r = new Random();
        int luckyNumber = r.nextInt(100) + 1;
        Scanner sc = new Scanner(System.in);
        //2.定义一个死循环 while 直到猜对了break
        while(true){
            //3.输入猜测的数字
            System.out.println("请输入猜测的数字：");
            int guessNum = sc.nextInt();
            if(guessNum == luckyNumber){
                System.out.println("恭喜你猜对了！");
                break;
            }else if(guessNum > luckyNumber){
                System.out.println("你猜的数字太大了");
            }else if(guessNum < luckyNumber){
                System.out.println("你猜的数字太小了");
            }
        }
        System.out.println("游戏已结束");
    }


}
